package com.jindy.module.warehouseKeeper.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.warehouseKeeper.domain.WarehouseKeeper;
import com.jindy.module.warehouseKeeper.service.IWarehouseKeeperService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 仓库管理员Controller
 * 
 * @author jindy
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/module/warehouseKeeper")
public class WarehouseKeeperController extends BaseController
{
    @Autowired
    private IWarehouseKeeperService warehouseKeeperService;

    /**
     * 查询仓库管理员列表
     */
    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseKeeper warehouseKeeper)
    {
        startPage();
        List<WarehouseKeeper> list = warehouseKeeperService.selectWarehouseKeeperList(warehouseKeeper);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理员列表
     */
    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:export')")
    @Log(title = "仓库管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseKeeper warehouseKeeper)
    {
        List<WarehouseKeeper> list = warehouseKeeperService.selectWarehouseKeeperList(warehouseKeeper);
        ExcelUtil<WarehouseKeeper> util = new ExcelUtil<WarehouseKeeper>(WarehouseKeeper.class);
        util.exportExcel(response, list, "仓库管理员数据");
    }

    /**
     * 获取仓库管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(warehouseKeeperService.selectWarehouseKeeperById(id));
    }


    /**
     * 根据管理员修改机器仓库信息
     */
//    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:update')")
    @PutMapping("/put/keeper")
    public AjaxResult updateWarehouseNameForMachine(WarehouseKeeper warehouseKeeper)
    {
        return warehouseKeeperService.updateWarehouseForMachine(warehouseKeeper);
    }

    /**
     * 新增仓库管理员
     */
    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:add')")
    @Log(title = "仓库管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseKeeper warehouseKeeper)
    {
        return toAjax(warehouseKeeperService.insertWarehouseKeeper(warehouseKeeper));
    }

    /**
     * 修改仓库管理员
     */
    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:edit')")
    @Log(title = "仓库管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseKeeper warehouseKeeper)
    {
        return toAjax(warehouseKeeperService.updateWarehouseKeeper(warehouseKeeper));
    }

    /**
     * 删除仓库管理员
     */
    @PreAuthorize("@ss.hasPermi('module:warehouseKeeper:remove')")
    @Log(title = "仓库管理员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(warehouseKeeperService.deleteWarehouseKeeperByIds(ids));
    }
}
